package com.taotaojs.myboot.service;

import com.taotaojs.myboot.bean.DemoOracleBean;
import com.taotaojs.myboot.mapper.oracle.OracleMapper;
import com.taotaojs.mybootsuper.ConfigConstant;
import com.taotaojs.mybootsuper.service.IMyComService;
import com.taotaojs.util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: TaoTaojs
 * @Date: 2019/3/13 23:35
 * @Description:
 * orcale测试Service类
 *
 * @关联类:
 * @参考链接：
 */
@Service
public class DemoOracleServiceImpl implements IMyComService<DemoOracleBean> {



    @Autowired
    private OracleMapper oracleMapper;

    public Integer batchInsertObject(List<DemoOracleBean> list){
        //分批次处理

        //当前次数
        int index = 1;
        //成功处理的数据条数
        int success = 0;
        List<DemoOracleBean> tempList = null;
        do {
            if(list.size() < index * ConfigConstant.BATCH_COUNT){
                //当剩余总量小于批次量的时候
                tempList = list.subList((index-1) * ConfigConstant.BATCH_COUNT, list.size());
            } else {
                tempList = list.subList((index-1) * ConfigConstant.BATCH_COUNT, index * ConfigConstant.BATCH_COUNT);
            }
            success += batchInsert(tempList);
        }while (index++ * ConfigConstant.BATCH_COUNT < list.size());
        return success;
    }

    private Integer batchInsert(List<DemoOracleBean> list){
        if(CollectionUtil.isEmpty(list)) {
            return 0;
        }
        return oracleMapper.insertSendTaskList(list);
    }

}
